package com.qipay.baas.mapper;

import com.qipay.baas.model.QipayTradlog;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface QipayTradlogMapper {
    @Delete({
        "delete from qipay_tradlog",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into qipay_tradlog (sp_id, channel_type, ",
        "sp_fee_recharge, qipay_amount, ",
        "sp_amount, trade_no, ",
        "total, remark, create_time)",
        "values (#{spId,jdbcType=BIGINT}, #{channelType,jdbcType=TINYINT}, ",
        "#{spFeeRecharge,jdbcType=DECIMAL}, #{qipayAmount,jdbcType=INTEGER}, ",
        "#{spAmount,jdbcType=INTEGER}, #{tradeNo,jdbcType=CHAR}, ",
        "#{total,jdbcType=INTEGER}, #{remark,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(QipayTradlog record);

    @InsertProvider(type=QipayTradlogSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(QipayTradlog record);

    @Select({
        "select",
        "id, sp_id, channel_type, sp_fee_recharge, qipay_amount, sp_amount, trade_no, ",
        "total, remark, create_time",
        "from qipay_tradlog",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="sp_id", property="spId", jdbcType=JdbcType.BIGINT),
        @Result(column="channel_type", property="channelType", jdbcType=JdbcType.TINYINT),
        @Result(column="sp_fee_recharge", property="spFeeRecharge", jdbcType=JdbcType.DECIMAL),
        @Result(column="qipay_amount", property="qipayAmount", jdbcType=JdbcType.INTEGER),
        @Result(column="sp_amount", property="spAmount", jdbcType=JdbcType.INTEGER),
        @Result(column="trade_no", property="tradeNo", jdbcType=JdbcType.CHAR),
        @Result(column="total", property="total", jdbcType=JdbcType.INTEGER),
        @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    QipayTradlog selectByPrimaryKey(Long id);

    @UpdateProvider(type=QipayTradlogSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(QipayTradlog record);

    @Update({
        "update qipay_tradlog",
        "set sp_id = #{spId,jdbcType=BIGINT},",
          "channel_type = #{channelType,jdbcType=TINYINT},",
          "sp_fee_recharge = #{spFeeRecharge,jdbcType=DECIMAL},",
          "qipay_amount = #{qipayAmount,jdbcType=INTEGER},",
          "sp_amount = #{spAmount,jdbcType=INTEGER},",
          "trade_no = #{tradeNo,jdbcType=CHAR},",
          "total = #{total,jdbcType=INTEGER},",
          "remark = #{remark,jdbcType=VARCHAR},",
          "create_time = #{createTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(QipayTradlog record);
}